import simpy

class Scheduler(object):
    def __init__(self,env,name,event):
        self.env = env
        self.name = name
        self.event = event


    def run(self):
        for i in range(15):
            yield self.event[0]

            print("time",self.env.now,",scheduler..."+self.name)
            # self.event.succeed()  # "reactivate



class ClockRun(object):
    def __init__(self,env,timeout,event,id):
        self.env = env
        self.timeout = timeout
        self.event = event
        self.id = id

    def run(self,env):
        for i in range(20):
            yield env.timeout(self.timeout)
            print("clock tick"+self.id+":",self.env.now)
            self.event[0].succeed()
            self.event[0] = env.event()







env = simpy.Environment()

schedule_event = [env.event()]

sc = Scheduler(env,"hello",schedule_event)
# event.callbacks.append(sc.run)
clockRun = ClockRun(env,2,schedule_event,'1')
clockRun2 = ClockRun(env,2,schedule_event,'2')

env.process(clockRun.run(env)) #进程产生
env.process(clockRun2.run(env)) #进程产生
env.process(sc.run())

env.run(schedule_event[0])
# print("step split....")
# T2 = env.now + 4
env.run(schedule_event[0])
# env.step()